local sk__shuixi = fk.CreateSkill {

  name = "sk__shuixi",

  tags = {  },

}



sk__shuixi:addEffect(fk.EventPhaseStart, {
  name = "sk__shuixi",
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__shuixi.name) and player.phase == Player.Start and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to, card = room:askForChooseCardAndPlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      ".|.|.|hand", "#sk__shuixi-choose", sk__shuixi.name, true)
    if #to > 0 and card then
      event:setCostData(self, {to[1], card})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self)[1])
    local suit = Fk:getCardById(event:getCostData(self)[2]):getSuitString(true)
    player:showCards(event:getCostData(self)[2])
    if to.dead then return end
    if player.dead or suit == "log_nosuit" then
      room:loseHp(to, 1, sk__shuixi.name)
      return
    end
    local all_choices = {"sk__shuixi_discard:::"..suit, "loseHp"}
    local choices = table.simpleClone(all_choices)
    local cards = table.filter(to:getCardIds("he"), function (id)
      return Fk:getCardById(id):getSuitString(true) == suit
    end)
    if #cards == 0 then
      table.remove(choices, 1)
    end
    local choice = room:askForChoice(to, choices, sk__shuixi.name, nil, false, all_choices)
    if choice == "loseHp" then
      room:loseHp(to, 1, sk__shuixi.name)
    else
      to:showCards(to:getCardIds("h"))
      if to.dead then return end
      cards = table.filter(cards, function (id)
        return Fk:getCardById(id):getSuitString(true) == suit and table.contains(to:getCardIds("he"), id)
      end)
      if #cards > 0 then
        room:throwCard(cards, sk__shuixi.name, to, to)
      end
    end
  end,
})

return sk__shuixi